<template>
	<view>
		<van-cell-group v-for="(item,index) in requestList.list">
			<van-cell :title="item.leaveName" :value="item.approveResult" size="large"
			is-link @click="signDetail()" :data-index="index" :data-id="item.requesterId"
				icon="cloud://cu4oral6-9g3l2orjbb347b4c.6375-cu4oral6-9g3l2orjbb347b4c-1307874055/群组.png" />
		</van-cell-group>
		
		<van-dialog id="van-dialog" />
	</view>
</template>

<script>
	import wrap from '@/components/wrap';
	import Dialog from '../../wxcomponents/vant/dialog/dialog';
	export default {
		data() {
			return {
				requestList: {
					"status": 1,
					"message": null,
					"data": null,
					"list": [{
						"id": 1,
						"requesterId": 3,
						"aimGroup": 1,
						"requestTime": "2021-11-01 23:33:11",
						"message": "拒绝考研，从我做起。",
						"leaveName": "17土木二班卢斌",
						"reviewer": 0,
						"judgeTime": null,
						"approveResult": "WAITING"
					}],
					"pageNum": 1,
					"pageSize": 3,
					"totalPage": 1,
					"lastPage": true,
					"firstPage": true
				},
				id:0
			}
		},
		methods: {
			//申请信息
			signDetail(e) {
				Dialog.alert({
					message: `申请信息：${this.requestList.list[e.target.dataset.index].message}\n
					申请时间：${this.requestList.list[e.target.dataset.index].requestTime}\n
					审批时间：${this.requestList.list[e.target.dataset.index].judgeTime}\n
					`,
					showCancelButton:"true",
					confirmButtonText:"同意",
					cancelButtonText:"拒绝",
					closeOnClickOverlay:"true"
				}).then(() => {
					uni.request({
						url: this.apiurl + '/user_join/judge_request', 
						header: {
							'Authorization': uni.getStorageSync('token') //自定义请求头信息
						},
						data: {
							requestId: e.target.dataset.id,
							result: "PERMISSION"
						},
						success: (res) => {
							console.log(res.data)
						}
					});
				}).catch(() => {
					uni.request({
						url: this.apiurl + '/user_join/judge_request', 
						header: {
							'Authorization': uni.getStorageSync('token') //自定义请求头信息
						},
						data: {
							requestId: e.target.dataset.id,
							result: "REJECTION"
						},
						success: (res) => {
							console.log(res.data)
						}
					});
				});
			},
			//查询和用户相关的加群申请
			findRequest() {
				uni.request({
					url: this.apiurl + '/user_join/group_request', //仅为示例，并非真实接口地址。
					header: {
						'Authorization': uni.getStorageSync('token') //自定义请求头信息
					},
					data: {
						groupId:this.id,
						pageNum: 1,
						pageSize: 3,
						result:""
					},
					success: (res) => {
						console.log(res.data)
						this.requestList = res.data
					}
				});
			}
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			console.log(option.id); //打印出上个页面传递的参数。
			this.id = option.id
			this.findRequest()
		}
	}
</script>

<style>

</style>
